package com.glsc.ngateway.common.base.domain.convert;

import javax.persistence.AttributeConverter;

public class WorkflowRequestlog_remark_Converter implements AttributeConverter<String, String> {


    @Override
    public String convertToDatabaseColumn(String attribute) {
        return attribute;
    }

    @Override
    public String convertToEntityAttribute(String dbData) {
        return dbData == null? null: delHtmlTags(dbData);
    }


    public static String delHtmlTags(String htmlStr){
        String scriptRegex="<script[^>]*?>[\\s\\S]*?<\\/script>";


        String styleRegex="<style[^>]*?>[\\s\\S]*?<\\/style>";
        //定义HTML标签的正则表达式，去除标签，只提取文字内容
        String htmlRegex="<[^>]+>";
        //定义空格,回车,换行符,制表符
        String spaceRegex = "\\s*|\t|\r|\n";

        String spaceHtml = "&nbsp";
        // 过滤script标签
        htmlStr = htmlStr.replaceAll(scriptRegex, "");
        // 过滤style标签
        htmlStr = htmlStr.replaceAll(styleRegex, "");
        // 过滤html标签
        htmlStr = htmlStr.replaceAll(htmlRegex, "");
        // 过滤空格等
        htmlStr = htmlStr.replaceAll(spaceRegex, "");
        htmlStr = htmlStr.replaceAll(spaceHtml, "");
        return htmlStr.trim(); // 返回文本字符串
    }
}
